﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufExtension.h"

namespace {
    class GnufButtonDefinitionImpl;
}

namespace gcmp
{
    class UniqueString;
    class CommandParameters;
}

namespace gnuf {
    class GNUF_EXTENSION_EXPORT GnufButtonDefinition
    {
        CANNOT_COPY_OR_ASSIGN(GnufButtonDefinition)
    public:
        GnufButtonDefinition(
            const wchar_t * key, 
            bool interactive,
            bool isDropDownButton,
            // Info
            const wchar_t * caption, 
            const wchar_t * tooltip, 
            const wchar_t * iconDir);
        GnufButtonDefinition(
            const wchar_t * key,
            bool interactive,
            bool isDropDownButton,
            // Info
            const wchar_t * caption,
            const wchar_t * tooltip,
            const wchar_t * iconDir,
            // Info2
            const wchar_t * caption2,
            const wchar_t * tooltip2,
            const wchar_t * iconDir2,
            // Toggle between Info and Info2
            bool wantToHandleToggling);
        virtual ~GnufButtonDefinition() {}

        // Override the original command. That is, when the button clicked, 
        // the passed-in command will execute, instead of the original one.
        void overrideCommandId(const std::wstring &);
        const std::wstring & overriddenCommandId() const;

        // Set if want to track clicking. If not tracked, the corresponding command
        // does not be executed by repeating last command. By default, it is true.
        void setWantToBeTracked(bool);
        bool wantToBeTracked() const;

        // Unselect all selected buttons.
        static void unselectSelectedButtons();

        friend class GnufButtonDefinitionImpl;
    protected:
        virtual void onPreClicked(const gcmp::UniqueString* location, gcmp::CommandParameters& commandParameters);

    private:
        gcmp::OwnerPtr< GnufButtonDefinitionImpl > m_impl;
    };
}

#define GNUF_BUTTON_DEFINITION(ClassName, CommandId, Interactive, Caption, ToolTip, IconDir) \
    static gnuf::GnufButtonDefinition s_gnfBntDef##ClassName( \
        CommandId, Interactive, false, \
        Caption, ToolTip, IconDir);

#define GNUF_BUTTON_DEFINITION_2(ClassName, CommandId, Interactive, Caption, ToolTip, IconDir, Caption2, ToolTip2, IconDir2, WantToHandleToggling) \
    static gnuf::GnufButtonDefinition s_gnfBntDef##ClassName( \
        CommandId, Interactive, false, \
        Caption, ToolTip, IconDir, \
        Caption2, ToolTip2, IconDir2, \
        WantToHandleToggling);
